<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <script src="../js/vue.global.js"></script>
    <title>简单登录</title>
</head>
<body>
    <div id="Application" style="text-align:center;">
        <h1>{{title}}</h1>

        <div v-if="!islogin">
            账号:<input type="text" v-model="username">
        </div>

        <div v-if="!islogin">
            密码:<input type="password" v-model="password">
        </div>

        <div>
            <button v-on:click="btnclick()">{{btnmsg}}</button>
        </div>
    </div>
    
    <script>
        const loginApp = {
            data()
            {
                return {
                    islogin: false,
                    username:"",
                    password:"",
                    btnmsg:"登录",
                    title:"欢迎您：未登录"
                }
            },
            methods:
            {
                btnclick()
                {
                    if(this.islogin)
                    {
                        this.logout()
                    }
                    else
                    {
                        this.login()
                    }
                },
                login()
                {
                    if(this.username.length > 0 && this.password.length > 0)
                    {
                        this.islogin = true
                        this.title = `欢迎您:${this.username}`
                        this.btnmsg = "注销"
                        this.username = ""
                        this.password = ""
                    }
                    else
                    {
                        alert("请输入账号密码");
                    }
                },
                logout()
                {
                    this.islogin = false
                    this.title = `欢迎您: 未登录`
                    this.btnmsg = "登录"
                    this.username = ""
                    this.password = ""
                }
            }
        }

        Vue.createApp(loginApp).mount("#Application");
    </script>
</body>
</html>